package com.bw.a3_27zk.login

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.base.entity.LoginEntityResult
import com.bw.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class LoginViewModel: BaseViewModel() {
    val loginSuccess = MutableLiveData<LoginEntityResult>()
    val loginFail = MutableLiveData<String>()
    fun login(map:MutableMap<String,String>){
        viewModelScope.launch {
            try {
                loginSuccess.value = apiService.login(map)
            } catch (e:Exception){
                loginFail.value = e.message
            }
        }
    }
    //注册
    val registerSuccess = MutableLiveData<LoginEntityResult>()
    val registerFail = MutableLiveData<String>()
    fun register(map:MutableMap<String,String>){
        viewModelScope.launch {
            try {
                registerSuccess.value = apiService.register(map)
            } catch (e:Exception){
                registerFail.value = e.message
            }
        }
    }
}